package cn.itcalvin.sncoal.cth.controller;

import cn.itcalvin.sncoal.cth.aspect.LogAnnotation;
import cn.itcalvin.sncoal.cth.aspect.RoleAnnotation;
import cn.itcalvin.sncoal.cth.pojo.common.ReqLong;
import cn.itcalvin.sncoal.cth.pojo.common.RespTotalRow;
import cn.itcalvin.sncoal.cth.pojo.common.RespUserInfo;
import cn.itcalvin.sncoal.cth.pojo.req.pf.*;
import cn.itcalvin.sncoal.cth.pojo.response.pf.*;
import cn.itcalvin.sncoal.cth.service.InfoPfService;
import cn.itcalvin.sncoal.cth.utils.JwtUtil;
import cn.itcalvin.vo.Message;
import cn.itcalvin.vo.MessageExt;
import cn.itcalvin.vo.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "评分管理")
@RestController
@RequestMapping("/api/pf")
public class PfController {
    @Resource
    InfoPfService infoPfService;

    @ApiOperation("评分列表查询-矿区、矿井不需要传入")
    @PostMapping("list")
    @LogAnnotation(value = "评分列表查询-矿区、矿井不需要传入")
    public Message<List<RespPfList>> list(@RequestBody @Valid ReqPfList reqPfList){
        final RespUserInfo userInfo = JwtUtil.getUserInfo();
        if(userInfo.getRoleType()==3){
            reqPfList.setMineId(reqPfList.getMineId());
        }else if (userInfo.getRoleType()==4){
            reqPfList.setMineId(userInfo.getBelongId());
        }else{
            return MessageUtil.error("参数错误！");
        }
        return infoPfService.list(reqPfList);
    }

    @ApiOperation(value = "新增")
    @PostMapping("add")
    @RoleAnnotation(value = "4")
    public Message add(@RequestBody @Valid ReqPfAdd reqPfAdd){
        return infoPfService.add(reqPfAdd);
    }

    @ApiOperation(value = "修改")
    @PostMapping("modify")
    @RoleAnnotation(value = "4")
    public Message modify(@RequestBody @Valid ReqPfModify reqPfModify){
        return infoPfService.modify(reqPfModify);
    }

    @ApiOperation(value = "删除")
    @PostMapping("delete")
    @RoleAnnotation(value = "4")
    public Message delete(@RequestBody @Valid ReqLong reqLong){
        return infoPfService.delete(reqLong);
    }


    @ApiOperation(value = "详情")
    @PostMapping("details")
    public Message<RespPfDetails> details(@RequestBody @Valid ReqLong reqLong){
        return infoPfService.details(reqLong);
    }

    @ApiOperation("某个任务的各个系统评分列表查询")
    @PostMapping("systemList")
    public MessageExt<List<RespPfListSystem>, RespTotalRow> systemList(@RequestBody @Valid ReqLong reqLong){
        return infoPfService.systemList(reqLong);
    }

    @ApiOperation(value = "某系统评价指标详情")
    @LogAnnotation(value = "某系统评价指标详情")
    @PostMapping("pfItemList")
    public Message<List<RespPfItemList>> pfItemList(@RequestBody @Valid ReqPfItemList reqPfItemList){
        return infoPfService.pfItemList(reqPfItemList);
    }

    @ApiOperation(value = "该系统是否已经提交")
    @PostMapping("pfItemListStateZp")
    public Message<RespPfItemState> pfItemListStateZp(@RequestBody @Valid ReqPfItemList reqPfItemList){
        return infoPfService.pfItemListState(reqPfItemList,1);
    }
    @ApiOperation(value = "该系统是否已经提交")
    @PostMapping("pfItemListStateHy")
    public Message<RespPfItemState> pfItemListStateHy(@RequestBody @Valid ReqPfItemList reqPfItemList){
        return infoPfService.pfItemListState(reqPfItemList,2);
    }


    @ApiOperation(value = "保存指标填写---核验和自评共用一个接口")
    @LogAnnotation(value = "保存指标填写---核验和自评共用一个接口")
    @PostMapping("savePfItemZp")
    @RoleAnnotation(value = "3,4")
    public Message savePfZbDetails(@RequestBody @Valid ReqPfSystemZbDetailsAdd reqPfSystemZbDetailsAdd){
        return infoPfService.savePfZbDetails(reqPfSystemZbDetailsAdd);
    }

    @ApiOperation(value = "提交某个系统的评分，一旦提交无法修改（入参是评分系统ID）")
    @LogAnnotation(value = "提交某个系统的评分，一旦提交无法修改")
    @PostMapping("commitPfSystem")
    @RoleAnnotation(value = "3,4")
    public Message commitPfSystem(@RequestBody @Valid ReqCommitPfSystem reqCommitPfSystem){
        return infoPfService.commitPfSystem(reqCommitPfSystem);
    }
    @ApiOperation(value = "批量提交-自评或者核验")
    @LogAnnotation(value = "批量提交-自评或者核验，一旦提交无法修改")
    @PostMapping("batchCommit")
    @RoleAnnotation(value = "3,4")
    public Message batchCommit(@RequestBody @Valid ReqBatchCommit reqBatchCommit){
        return infoPfService.batchCommit(reqBatchCommit);
    }

    @ApiOperation(value = "批量驳回-自评或者核验")
    @LogAnnotation(value = "批量驳回-自评或者核验")
    @PostMapping("batchBhCommit")
    @RoleAnnotation(value = "3,4")
    public Message batchBhCommit(@RequestBody @Valid ReqBatchCommit reqBatchCommit){
        return infoPfService.batchBhCommit(reqBatchCommit);
    }
    @ApiOperation(value = "提交任务-自评或者核验")
    @LogAnnotation(value = "提交任务-自评或者核验")
    @PostMapping("batchTaskCommit")
    @RoleAnnotation(value = "3,4")
    public Message batchTaskCommit(@RequestBody @Valid ReqBatchCommit reqBatchCommit){
        return infoPfService.batchTaskCommit(reqBatchCommit);
    }

    @ApiOperation(value = "针对某个任务进行复制")
    @LogAnnotation(value = "针对某个任务进行复制")
    @PostMapping("copyPfTask")
    @RoleAnnotation(value = "4")
    public Message copyPfTask(@RequestBody @Valid ReqPfCopy reqPfCopy){
        return infoPfService.copyPfTask(reqPfCopy);
    }

    @ApiOperation(value = "上传整改计划文件")
    @LogAnnotation(value = "上传整改计划文件")
    @PostMapping("uploadZgjh")
    @RoleAnnotation(value = "4")
    public Message uploadZgjh(@RequestBody @Valid ReqUploadZgjh reqUploadZgjh){
        return infoPfService.uploadZgjh(reqUploadZgjh);
    }



}
